import {Injectable} from "@angular/core";
import {RequestServerHTTPService} from "../../../shared/service/request-server-HTTP.service";
import {UserModel} from "../../../shared/model/user.model";
import {Observable} from "rxjs/Observable";
import {ResultEntity} from "../../../shared/model/resultEntity";

/**
 * 用户登录时用于访问后台服务器的服务
 * Created by Administrator on 2016/12/3.
 */
@Injectable()
export class LoginInHttpService {
    private readonly loginURL: string = "user/loginIn.do";

    constructor(private requestServerHttpService: RequestServerHTTPService) {
    }

    login(user: UserModel): Observable<any> {
        return Observable.create((observer) => {
            this.requestServerHttpService.getRequestServerForBack(this.loginURL, user,
                (data: ResultEntity) => {
                    observer.next(data.result)
                },
                (error) => {
                    observer.error(error)
                });
        });
    }
}
